/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup Sensor
 * @{
 *
 * @brief Provides APIs for sensor services to access the sensor driver.
 *
 * A sensor service can obtain a sensor driver object or agent and then call APIs provided by this object or agent to
 * access different types of sensor devices, thereby obtaining sensor information,
 * subscribing to or unsubscribing from sensor data, enabling or disabling a sensor,
 * setting the sensor data reporting mode, and setting sensor options such as the accuracy and measurement range.
 * 
 *
 * @since 2.2
 */

/**
 * @file sensor_if.h
 *
 * @brief Declares the APIs provided by the sensor module for obtaining sensor information, subscribing to or
 * unsubscribing from sensor data, enabling or disabling a sensor, setting the sensor data reporting mode,
 * and setting sensor options such as the accuracy and measurement range.
 * 
 *
 * @since 2.2
 * @version 1.0
 */

#ifndef SENSOR_IF_H
#define SENSOR_IF_H

#include "sensor_type.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

/**
 * @brief Defines the interface for performing basic operations on sensors.
 *
 * The operations include obtaining sensor information, subscribing to or unsubscribing from sensor data,
 * enabling or disabling a sensor, setting the sensor data reporting mode, and setting sensor options such as
 * the accuracy and measurement range.
 */
struct SensorInterface {
    /**
     * @brief Obtains information about all sensors in the system.
     *
     * @param sensorInfo Indicates the double pointer to the information about all sensors in the system.
     * The information about a sensor generally includes the sensor name, sensor vendor, firmware version,
     * hardware version, sensor type ID, sensor ID, maximum measurement range, accuracy, and power. For details,
     * see {@link SensorInformation}.
     * @param count Indicates the pointer to the total number of sensors in the system.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns a negative value if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*GetAllSensors)([out] struct SensorInformation **sensorInfo, [out] int32_t *count);

    /**
     * @brief Enables a sensor available in the sensor list.
     * Subscribers can obtain sensor data only after the sensor is enabled.
     *
     * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns a negative value if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*Enable)([in] int32_t sensorId);

    /**
     * @brief Disables a sensor.
     *
     * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns a negative value if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*Disable)([in] int32_t sensorId);

    /**
     * @brief Sets the data sampling interval and data reporting interval for a sensor.
     *
     * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
     * @param samplingInterval Indicates the sensor data sampling interval to set, in nanoseconds.
     * @param reportInterval Indicates the sensor data reporting interval to set, in nanoseconds.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns a negative value if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*SetBatch)([in] int32_t sensorId, [in] int64_t samplingInterval, [in] int64_t reportInterval);

    /**
     * @brief Sets the data reporting mode for a sensor.
     *
     * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
     * @param mode Indicates the data reporting mode to set. For details, see {@link SensorModeType}.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns a negative value if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*SetMode)([in] int32_t sensorId, [in] int32_t mode);

    /**
     * @brief Sets options for a sensor, including its measurement range and accuracy.
     *
     * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}.
     * @param option Indicates the options to set, such as the measurement range and accuracy.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns <b>0</b> if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*SetOption)([in] int32_t sensorId, [in] uint32_t option);

    /**
     * @brief Registers a callback for reporting sensor data.
     *
     * @param groupId Indicates the sensor group ID.
     * If <b>groupId</b> is set to a value within the range 128-160, this function is used to
     * register a callback for reporting data of medical sensors.
     * You only need to register a callback once for all medical sensors.
     * If <b>groupId</b> is set to a value outside the range 128-160, this function is used to
     * register a callback for reporting data of traditional sensors.
     * You only need to register a callback once for all traditional sensors.
     * @param cb Indicates the callback to register. For details, see {@link RecordDataCallback}.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns a negative value if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*Register)([in] int32_t groupId, [in] RecordDataCallback cb);

    /**
     * @brief Deregisters a callback for reporting sensor data.
     *
     * @param groupId Indicates the sensor group ID.
     * If <b>groupId</b> is set to a value within the range 128-160, this function is used to
     * register a callback for reporting data of medical sensors.
     * You only need to deregister a callback once for all medical sensors.
     * If <b>groupId</b> is set to a value outside the range 128-160, this function is used to
     * register a callback for reporting data of traditional sensors.
     * You only need to deregister a callback once for all traditional sensors.
     * @param cb Indicates the callback to deregister. For details, see {@link RecordDataCallback}.
     *
     * @return Returns <b>0</b> if the operation is successful.
     * @return Returns a negative value if the operation fails.
     *
     * @since 2.2
     * @version 1.0
     */
    int32_t (*Unregister)([in] int32_t groupId, [in] RecordDataCallback cb);
};

/**
 * @brief Creates a <b>SensorInterface</b> instance.
 *
 * @return Returns a non-zero value if the operation is successful.
 * @return Returns a negative value if the operation fails.
 *
 * @since 2.2
 * @version 1.0
 */
const struct SensorInterface *NewSensorInterfaceInstance(void);

/**
 * @brief Releases this <b>SensorInterface</b> instance.
 *
 * @return Returns <b>0</b> if the operation is successful.
 * @return Returns a negative value if the operation fails.
 * 
 * @since 2.2
 * @version 1.0
 */
int32_t FreeSensorInterfaceInstance(void);

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

#endif /* SENSOR_IF_H */
/** @} */
